﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace StateManager
{
    class MenuItems
    {
        string text;

        Vector2 Pos;

        public string Text
        {
            get { return text; }
            set { text = value; }
        }

        public Vector2 Position
        {
            get { return Pos; }
            set { Pos = value; }
        }


        public event EventHandler<PlayerEventHandler> Selected;

        protected internal virtual void OnSelectEntry(PlayerIndex playerIndex)
        {
            if (Selected != null)
                Selected(this, new PlayerEventHandler(playerIndex));
        }

        public MenuItems(string text)
        {
            this.text = text;
        }

        public virtual void Update(GenericMenu screen, bool isSelected, GameTime gameTime)
        {
            
        }

        public virtual void Draw(GenericMenu screen, bool isSelected, GameTime gameTime)
        {

            // draw the selected menu entry in yellow, otherwise keep it white
            Color color = isSelected ? Color.Yellow : Color.Red;


            float scale = 1;


            // draw text
            SManager screenManager = screen.SManager;
            SpriteBatch spriteBatch = screenManager.SpriteBatch;
            SpriteFont font = screenManager.SpriteFont;

            Vector2 origin = new Vector2(0, font.LineSpacing / 2);

            spriteBatch.DrawString(font, text, Pos, color, 0,
                                   origin, scale, SpriteEffects.None, 0);
        }

        public virtual int GetHeight(GenericMenu screen)
        {
            return screen.SManager.SpriteFont.LineSpacing;
        }


        public virtual int GetWidth(GenericMenu screen)
        {
            return (int)screen.SManager.SpriteFont.MeasureString(Text).X;
            // gets width of text 
        }
    }
}
